package org.toves.checklua;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.toves.checklua.ast.AstProcessorResult;
import org.toves.checklua.ast.Complaint;

public class CheckerResult implements AstProcessorResult {
	private List<Complaint> complaints;
	private List<AstProcessorResult> results;
	
	public CheckerResult() {
		complaints = new ArrayList<Complaint>();
		results = new ArrayList<AstProcessorResult>();
	}
	
	public boolean containsError() {
		for (Complaint c : complaints) {
			if (c.getLevel() == Complaint.ERROR) {
				return true;
			}
		}
		return false;
	}
	
	void addComplaint(Complaint complaint) {
		complaints.add(complaint);
	}
	
	void addResult(AstProcessorResult result) {
		complaints.addAll(result.getComplaints());
		results.add(result);
	}
	
	public List<Complaint> getComplaints() {
		return Collections.unmodifiableList(complaints);
	}
	
	public void commit() {
		for (AstProcessorResult result : results) {
			result.commit();
		}
	}
}
